<?php namespace Common\Tag;
use Hdphp\View\TagBase;
/**
 * 自定义标签
 *
 */
class Common extends TagBase{
		/**
		 * 标签声明
		 * @var array
		 */
		public $tags = array(
				//block说明 1：块标签  0：行标签
				'category' => array('block' => 1, 'level' => 4),
				'article' => array('block' => 1, 'level' => 4),
				'tag' => array('block' => 1, 'level' => 4),
				'link' => array('block' => 1, 'level' => 4)
		);
		
		/**
		 * 分类标签【自定义】
		 * @param $attr 属性
		 * @param $content 内容
		 * @param $hd HdView模型引擎对象
		 */
		public function _category($attr, $content, &$hd){
				$pid = isset($attr['pid']) ? $attr['pid'] : null;
				$where = '';
				if (!is_null($pid)) {
					 $where = "->where(array('pid' => {$pid}))";
				}
				$str=<<<str
				<?php 
					\$model = new \Common\Model\Category();
					\$articleModel = new \Common\Model\Article();
					\$data = \$model{$where}->get();
					foreach(\$data as \$field):
					//列表页地址
					\$field['url'] =__ROOT__ .  "/l_c_". \$field['cid'] . ".html";
					\$field['total'] = \$articleModel->where("category_cid={\$field['cid']} and is_recycle=0")->count();
				?>
					$content 
				<?php endforeach;?>
str;
				return $str;
		}
		
		/**
		 * 文章标签【自定义】
		 * @param $attr 属性
		 * @param $content 内容
		 * @param $hd HdView模型引擎对象
		 */
		public function _article($attr, $content, &$hd){
				$limit = isset($attr['limit']) ? $attr['limit'] : 2;
				$order = isset($attr['order']) ? $attr['order'] : 'sendtime';
				$limit = "->limit($limit)";
				$str=<<<str
				<?php 
					\$model = new \Common\Model\Article();
					\$data = \$model->field('aid,title,sendtime,digest,thumb,imgs')->where("is_recycle=0")->orderBy('{$order}','DESC'){$limit}->get();
					foreach(\$data as \$field):
					//列表页地址
					\$field['url'] = U('lists/index',array('aid'=>\$field['aid']));
				?>
					$content 
				<?php endforeach;?>
str;
				return $str;
		}
		
		/**
		 * 标签云标签【自定义】
		 * @param $attr 属性
		 * @param $content 内容
		 * @param $hd HdView模型引擎对象
		 */
		public function _tag($attr, $content, &$hd){
				$str=<<<str
				<?php 
					\$model = new \Common\Model\Tag();
					\$data = \$model->get();
					foreach(\$data as \$field):
					//列表页地址
					\$field['url'] = __ROOT__ . "/l_tag_". \$field['tid'] . ".html";
				?>
					$content 
				<?php endforeach;?>
str;
				return $str;
		}
		
		/**
		 * 友情链接标签【自定义】
		 * @param $attr 属性
		 * @param $content 内容
		 * @param $hd HdView模型引擎对象
		 */
		public function _link($attr, $content, &$hd){
			$str=<<<str
				<?php
					\$model = new \Common\Model\Link();
					\$data = \$model->get();
					foreach(\$data as \$field):
				?>
					$content
				<?php endforeach;?>
str;
			return $str;
		}
}